package cn.kgc.spring01.service;

import cn.kgc.spring01.factory.BeanFactory;
import cn.kgc.spring01.mapper.NewUserMapperImpl;
import cn.kgc.spring01.mapper.UserMapper;
import cn.kgc.spring01.mapper.UserMapperImpl;

/**
 * @author: mosin
 * @version: v1.0  2022/11/28
 *
 * 业务层和持久层有依赖关系  强耦合关系
 * 23中设计模式中  工厂模式  实现代码解耦
 *面向接口编程  可以减少代码耦合
 *
 */
public class UserServiceImpl implements UserService {

    /*
    * 问题：切换数据库 需要改变实现类的对象   修改源码  违被编程开闭原则  代码的修改关闭 开放代码扩展
        分析： 使用new关键词创建对象 硬编码
    * */
    //private UserMapper userMapper = new UserMapperImpl();
    //private UserMapper userMapper = new NewUserMapperImpl();

    //固定类型的实现类对象
    //private UserMapper  userMapper = BeanFactory.getUserMapper();

    // 获取指定类型的实现类对象
    //private UserMapper  userMapper = BeanFactory.getUserMapper("cn.kgc.spring01.mapper.UserMapperImpl");
    //private UserMapper  userMapper = BeanFactory.getUserMapper("cn.kgc.spring01.mapper.NewUserMapperImpl");
    //private UserMapper  userMapper = (UserMapper) BeanFactory.getBean("cn.kgc.spring01.mapper.UserMapperImpl");

    private UserMapper userMapper = BeanFactory.getBean("newMapperImpl", NewUserMapperImpl.class);


    public Integer  deleteById(Integer id){

        Integer line = userMapper.deleteById(id);
        return line;

    }


}
